<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace Move\Controller;

/**
 * Description of PublicController
 *
 * @author gc
 */
class PublicController extends CommonController
{

    protected function _initialize()
    {
        
    }

    //登录页
    public function login()
    {

        $this->display();
    }

    //验证登录
    public function checkLogin()
    {
        $username = I("username");
        $password = I("password");

        $map['phone'] = $username;
        $map['status'] = array('egt', 0);
        $user = M("Introducer")->where($map)->find();

        if (empty($user) || $user['status'] == 0) {
            $this->error('用户不存在或被禁用！');
        }

        if ($user['password'] != $password) {
            $this->error('密码错误！');
        }

        $this->uid = $user['id'];
        session('user', $user);

        $this->success('登录成功！', U('Index/index'));
    }

    /* 退出登录 */

    public function logout()
    {
        if (!empty($this->uid)) {
            session('[destroy]');
            $this->success('退出成功！', U('login'));
        } else {
            $this->redirect('login');
        }
    }

}
